import Vue from 'vue'
import Vuex from 'vuex'
import ad from 'vuex-persistedstate'
Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    dlList:[]
  },
  mutations: {
    // 添加任务的方法
    dlGet(state,k){
      state.dlList.push(k)
    },
    // 删除任务的方法
    dldel(state,key){
      state.dlList.splice(key,1)
    },
    // 改变复选框
    dlint(state,key){
      state.dlList[key].flag=!state.dlList[key].flag
    },
    // 删除所选
    dldelall(state){
      for(let i = 0; i < state.dlList.length; i++){
        if(state.dlList[i].flag){
          state.dlList.splice(i,1);
          i--;
        }
      }
    },
    // 全选
    dlquan(state,fg){
      state.dlList.forEach((i,k)=>{
        i.flag=fg
      })
    },
    dlshow(state,k){
      state.dlList[k].dlshow = true;
    },
    dlhide(state,k){
      state.dlList[k].dlshow = false;
    }
  },
  actions: {
  },
  modules: {
  },
  getters:{
    dlxnum(state){
      var num = 0
      state.dlList.forEach((i,k)=>{
        if(i.flag==true){
          num++
        }
      })
      return num
    },
    dlnum(state){
      var num =0
      state.dlList.forEach((i,k)=>{
        num++
      })
      return num
    }
  },
  plugins:[ad()]
})
